package com.gin.no_gay_alliance.viewmodel.emote;

import android.os.Parcel;
import android.os.Parcelable;

import com.gin.nga.response.emote.Emote;
import com.gin.nga.response.field.Attachment;

import java.util.Locale;

/**
 * 表情
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/8/27 21:53
 **/
public class EmoteModel implements Parcelable {
    public static final Creator<EmoteModel> CREATOR = new Creator<EmoteModel>() {
        @Override
        public EmoteModel createFromParcel(Parcel in) {
            return new EmoteModel(in);
        }

        @Override
        public EmoteModel[] newArray(int size) {
            return new EmoteModel[size];
        }
    };
    /**
     * 插入到正文的代码
     */
    public String code;
    /**
     * 显示在表情栏中的图片地址
     */
    public String url;
    /**
     * 使用次数(仅在"常用"组用于排序)
     */
    public Integer count;

    public EmoteModel(Emote emote) {
        this.code = emote.getBbsCode();
        this.url = emote.getUrl();
    }

    public EmoteModel(ThirdPartyEmote thirdPartyEmote) {
        this.code = String.format(Locale.CHINA, "[img]%s[/img]", thirdPartyEmote.img);
        this.url = Attachment.PREFIX + thirdPartyEmote.img.substring(2);
    }

    protected EmoteModel(Parcel in) {
        code = in.readString();
        url = in.readString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(code);
        dest.writeString(url);
    }
}
